Skip to content

let's integreate intercom with newtab#327

Open
shivammittal274 wants to merge 2 commits intomainfrom
feat/-qTW5pyG-lets-integreate-intercom-with-newtab
Open

let's integreate intercom with newtab#327
shivammittal274 wants to merge 2 commits intomainfrom
feat/-qTW5pyG-lets-integreate-intercom-with-newtab

Conversation

@shivammittal274
Copy link
Contributor

Summary

let's integreate intercom with newtab

Changes

apps/agent/.env.example                            |   1 +
 apps/agent/entrypoints/app/main.tsx                |  11 +-
 apps/agent/entrypoints/intercom.sandbox/index.html |  17 +++
 apps/agent/entrypoints/intercom.sandbox/main.ts    | 101 +++++++++++++++++
 apps/agent/lib/env.ts                              |   1 +
 apps/agent/lib/intercom/IntercomProvider.tsx       | 119 +++++++++++++++++++++
 apps/agent/lib/intercom/intercom.ts                |  57 ++++++++++
 apps/agent/wxt.config.ts                           |  11 ++
 8 files changed, 314 insertions(+), 4 deletions(-)

Agent Metadata

  • Total cost: $8.1112
  • Stages:
    • ok setup ($0.0000, 40.1s)
    • ok plan ($3.9050, 887.6s)
    • ok implement ($4.2062, 1030.6s)

Generated by coding-agent v3

@github-actions
Copy link
Contributor

Thank you for your contribution! Before we can merge this PR, we need you to sign our Contributor License Agreement.

To sign the CLA, please add a comment to this PR with the following text:

I have read the CLA Document and I hereby sign the CLA

You only need to sign once. After signing, this check will pass automatically.


Troubleshooting
  • Already signed but still failing? Comment recheck to trigger a re-verification.
  • Signed with a different email? Make sure your commit email matches your GitHub account email, or add your commit email to your GitHub account.
- - - I have read the CLA Document and I hereby sign the CLA - - - **BrowserOS Coding Agent** seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please [add the email address used for this commit to your account](https://help.github.com/articles/why-are-my-commits-linked-to-the-wrong-user/#commits-are-not-linked-to-any-user).
You can retrigger this bot by commenting **recheck** in this Pull Request. Posted by the **CLA Assistant Lite bot**.

@claude
Copy link

claude bot commented Feb 11, 2026

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 11, 2026

Greptile Overview

Greptile Summary

This PR adds an Intercom integration to the extension’s new tab app by wrapping the React tree in an IntercomProvider. The provider renders a fixed-position sandbox iframe (intercom.html) and communicates with it via postMessage to boot Intercom, update identity based on useSessionInfo(), and track open/close events. A new sandbox entrypoint loads the Intercom widget script and forwards basic lifecycle events back to the parent. The manifest config is updated with a sandbox CSP to allow Intercom’s resources, and a new VITE_PUBLIC_INTERCOM_APP_ID env var is introduced.

Confidence Score: 3/5

  • This PR is mergeable after fixing message validation and initial identity sync reliability.
  • Core integration approach is reasonable, but current postMessage usage lacks sender/origin validation and the provider can miss syncing identity when session loads before the iframe boots. These are real security/correctness issues to address before merging.
  • apps/agent/lib/intercom/IntercomProvider.tsx, apps/agent/entrypoints/intercom.sandbox/main.ts

Important Files Changed

Filename Overview
.gitignore Adds .agent/ to gitignore; low risk.
apps/agent/.env.example Adds VITE_PUBLIC_INTERCOM_APP_ID example env var; low risk.
apps/agent/entrypoints/app/main.tsx Wraps app in IntercomProvider; behavior change is straightforward.
apps/agent/entrypoints/intercom.sandbox/index.html Adds sandbox HTML entrypoint to load TS module; ensure it’s packaged as intercom.html.
apps/agent/entrypoints/intercom.sandbox/main.ts Implements Intercom sandbox boot/update via postMessage; currently uses '*' targetOrigin and doesn’t validate sender.
apps/agent/lib/env.ts Extends env schema with optional VITE_PUBLIC_INTERCOM_APP_ID; low risk.
apps/agent/lib/intercom/IntercomProvider.tsx Adds provider injecting Intercom sandbox iframe and syncing session identity; has sender/origin validation gaps and may miss initial identity sync if iframe loads late.
apps/agent/lib/intercom/intercom.ts Adds typed message/event definitions and sandbox event guard; guard only checks type string.
apps/agent/wxt.config.ts Adds CSP sandbox directives to allow Intercom resources; verify this matches Chrome extension CSP expectations and doesn’t over-broaden policies.

Sequence Diagram

sequenceDiagram
  participant NewTab as NewTab (app entrypoint)
  participant Provider as IntercomProvider (React)
  participant Intercom as Intercom JS bootstrap
  participant iframe as Sandbox iframe (intercom.sandbox)

  NewTab->>Provider: Render app
  Provider->>Intercom: init(appId)
  Intercom->>iframe: create hidden iframe + inject script
  iframe->>Intercom: postMessage "intercom-ready"
  Provider->>Intercom: update(user/context)
  Intercom-->>NewTab: ready/event callbacks
Loading

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

9 files reviewed, 3 comments

Edit Code Review Agent Settings | Greptile

Comment on lines +1 to +3
import type { FC, PropsWithChildren } from 'react'
import { useEffect, useRef, useState } from 'react'
import { useSessionInfo } from '@/lib/auth/sessionStorage'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sandbox boot may be missed
If sessionInfo resolves before the iframe onLoad fires, the identity sync effect posts intercom:update while iframeWindowRef.current is still null, and there’s no retry after boot. In that scenario, Intercom will boot without user identity until a later session change occurs. Consider sending an intercom:update after intercom:ready (or after handleIframeLoad) when sessionInfo.user is already available.

Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/agent/lib/intercom/IntercomProvider.tsx
Line: 1:3

Comment:
**Sandbox boot may be missed**
If `sessionInfo` resolves before the iframe `onLoad` fires, the identity sync effect posts `intercom:update` while `iframeWindowRef.current` is still `null`, and there’s no retry after boot. In that scenario, Intercom will boot without user identity until a later session change occurs. Consider sending an `intercom:update` after `intercom:ready` (or after `handleIframeLoad`) when `sessionInfo.user` is already available.


How can I resolve this? If you propose a fix, please make it concise.

Comment on lines +27 to +30
const [isMessengerOpen, setIsMessengerOpen] = useState(false)
const { sessionInfo, isLoading } = useSessionInfo()

const handleIframeLoad = () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

postMessage accepts any origin
postMessage(..., '*') combined with a sandbox that also posts with '*' means any frame/window can spoof intercom:* messages to this page. Even though the listener checks type, it doesn’t verify event.source === iframeRef.current?.contentWindow (or an expected origin), so a malicious page could toggle state or trigger shutdown/update. Tighten validation to only accept messages from the sandbox iframe window.

Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/agent/lib/intercom/IntercomProvider.tsx
Line: 27:30

Comment:
**postMessage accepts any origin**
`postMessage(..., '*')` combined with a sandbox that also posts with `'*'` means any frame/window can spoof `intercom:*` messages to this page. Even though the listener checks `type`, it doesn’t verify `event.source === iframeRef.current?.contentWindow` (or an expected origin), so a malicious page could toggle state or trigger shutdown/update. Tighten validation to only accept messages from the sandbox iframe window.


How can I resolve this? If you propose a fix, please make it concise.

Comment on lines +13 to +16
parent.postMessage(message, '*')
}

function initIntercomStub() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

postMessage targetOrigin too broad
The sandbox sends events via parent.postMessage(message, '*'), which allows any embedding origin to receive Intercom state events if this page is ever embedded outside the extension context. Since the parent is expected to be the extension page, pass an explicit targetOrigin (or at least validate event.origin on the parent side and restrict event.source).

Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/agent/entrypoints/intercom.sandbox/main.ts
Line: 13:16

Comment:
**postMessage targetOrigin too broad**
The sandbox sends events via `parent.postMessage(message, '*')`, which allows any embedding origin to receive Intercom state events if this page is ever embedded outside the extension context. Since the parent is expected to be the extension page, pass an explicit `targetOrigin` (or at least validate `event.origin` on the parent side and restrict `event.source`).


How can I resolve this? If you propose a fix, please make it concise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant